package org.java.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.java.Service.CategoryService;
import org.java.common.Result;
import org.java.entity.Category;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author :王特
 * @create: 2022/07/14 18:40
 */
@RestController
@Slf4j
@RequestMapping("/pro")
public class controller {
//    @Autowired
//    private proFeign proFeign;
@Autowired
private CategoryService categoryService;

    @GetMapping("/list")
    public Result<List<Category>> categoryshow(Category category){
        LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
        //  只有当 category.getType()不为空，才会比较 前端传入的category的type和 实体类中 type属性是否相等
        queryWrapper.eq(category.getType() != null, Category::getType,category.getType());

        queryWrapper.orderByAsc(Category::getSort).orderByDesc(Category::getUpdateTime);

        List<Category> list = categoryService.list(queryWrapper);

        return Result.success(list);
    }
}
